package cn.wolfcode.shop.util;


import org.apache.commons.codec.digest.DigestUtils;

import java.util.UUID;

public class MD5Util {
    public static final String salt = "1a2b3c4d";

    /**
     * 模拟前端加密过程
     * @param password
     * @return
     */
    public static String inputPassToFormPass(String password){
        return DigestUtils.md5Hex(""+salt.charAt(0)+salt.charAt(2)+password+salt.charAt(4)+salt.charAt(5));
    }

    /**
     * 拿到前端传过来的密文,对密文进行加盐加密====>密文
     * @param password
     * @param salt
     * @return
     */
    public static String formPassToDbPass(String password,String salt){
        return DigestUtils.md5Hex(""+salt.charAt(0)+salt.charAt(1)+password+salt.charAt(2)+salt.charAt(3));
    }

    public static void main(String[] args) {
        String input = "123456";
        String formPass = inputPassToFormPass(input);
        String salt = UUID.randomUUID().toString().replace("-","").substring(0,6);
        System.err.println("salt:"+ salt);
        String dbPass = formPassToDbPass(formPass, salt);
        System.err.println(dbPass);
    }
}
